import Koa from 'koa'
// @ts-expect-error 没有这个@types
import koaOnerror from 'koa-onerror'
import koaStatic from 'koa-static'
import koaJson from 'koa-json'
import koaLogger from 'koa-logger'
import koaCors from 'koa-cors'
import koaBodyparser from 'koa-bodyparser'
// import { connection } from '@/utils/mySqlConnection'
import useRouter from '@/routes/index'
import { customError } from './middleWare/error'
import { permission } from './middleWare/permission'
import { dataSource } from './utils/typeormConnect'

const app = new Koa()
app.use(koaStatic('@/src/public'))
app.use(koaJson())
app.use(koaLogger())
app.use(koaCors())
app.use(koaBodyparser({
    enableTypes: ['json', 'form', 'text']
}))

app.use(customError())
app.use(permission())
koaOnerror(app)
useRouter(app)

dataSource.initialize()
// connection.connect()
app.listen(3000)

console.clear()
console.log('后端执行地址：http://localhost:3000')

// sendMail('1548720321@qq.com')
